package com.zjhd.sealcutting.controller;

import com.zjhd.sealcutting.domain.ExpressInfo;
import com.zjhd.sealcutting.param.ExpressSearchQuery;
import com.zjhd.sealcutting.service.ExpressInfoService;
import com.zjhd.sealcutting.utils.OperLog;
import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import com.zjhd.sealcutting.vo.ExpressInfoVo;
import com.zjhd.sealcutting.vo.SearchResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO  快递管理
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/11/25 17:53
 */
@Api(value = "快递管理", tags = "快递管理")
@RequestMapping("/express")
@RestController
public class ExpressInfoController {

    private final static Logger logger = LoggerFactory.getLogger(ExpressInfoController.class);

    @Autowired
    private ExpressInfoService expressInfoService;

    @ApiOperation(value = "分页查询快递列表接口", notes = "分页查询快递列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courierNumber", value = "快递单号", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "页大小", defaultValue = "10", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "页码", defaultValue = "1", dataType = "String", paramType = "query")
    })
    @GetMapping("/queryExpressParamlist")
    public ResponseResult<SearchResult<ExpressInfo>> queryExpressParamlist(ExpressSearchQuery param){
        try{
            return ResultGenerator.genSuccessResult(expressInfoService.queryExpressParamlist(param));
        }catch (Exception ex) {
            logger.error("分页查询快递列表接口失败", ex);
            return ResultGenerator.genFailResult("分页查询快递列表接口失败");
        }
    }

    @ApiOperation(value = "新增快递", notes = "新增快递接口")
    @PostMapping("/insertExpressInfo")
    @OperLog(operModul = "快递管理-新增快递",operType = "新增",operDesc = "新增快递")
    public ResponseResult insertExpressInfo(@RequestBody ExpressInfoVo expressInfoVo){
        try{
            return ResultGenerator.genSuccessResult(expressInfoService.insertExpressInfo(expressInfoVo));
        }catch (Exception ex) {
            logger.error("新增快递接口失败", ex);
            return ResultGenerator.genFailResult("新增快递接口失败");
        }
    }

    @ApiOperation(value = "修改快递", notes = "修改快递接口")
    @PostMapping("/updateExpressInfo")
    @OperLog(operModul = "快递管理-修改快递",operType = "修改",operDesc = "修改快递")
    public ResponseResult updateExpressInfo(@RequestBody ExpressInfoVo expressInfoVo){
        try{
            return ResultGenerator.genSuccessResult(expressInfoService.updateExpressInfo(expressInfoVo));
        }catch (Exception ex) {
            logger.error("修改快递接口失败", ex);
            return ResultGenerator.genFailResult("修改快递接口失败");
        }
    }

    @ApiOperation(value = "删除快递", notes = "删除快递接口")
    @PostMapping("/deleteExpressInfo")
    @OperLog(operModul = "快递管理-删除快递",operType = "删除",operDesc = "删除快递")
    public ResponseResult deleteExpressInfo(@RequestParam(value = "id",defaultValue = "")Integer id){
        try{
            return ResultGenerator.genSuccessResult(expressInfoService.deleteExpressInfo(id));
        }catch (Exception ex) {
            logger.error("删除快递接口失败", ex);
            return ResultGenerator.genFailResult("删除快递接口失败");
        }
    }

    @ApiOperation(value = "查询快递信息详情", notes = "查询快递信息详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "快递ID", dataType = "Long", paramType = "query")
    })
    @GetMapping("/queryByIdExpressInfo")
    @OperLog(operModul = "快递管理-查看快递",operType = "查询",operDesc = "查看快递信息详情")
    public ResponseResult queryByIdExpressInfo(Integer id){
        try{
            return ResultGenerator.genSuccessResult(expressInfoService.queryByIdExpressInfo(id));
        }catch (Exception ex) {
            logger.error("查询快递信息详情接口失败", ex);
            return ResultGenerator.genFailResult("查询快递信息详情接口失败");
        }
    }
}
